import plotly.graph_objects as go
import numpy as np
import sympy as sp

# 定义变量
x = sp.symbols("x")
# 定义函数
f = (1 + 1 / x) ** x

# 求x在正无穷极限
limit_inf = sp.limit(f, x, sp.oo)
print("x在正无穷极限:", limit_inf)

# 可视化显示
x_values = np.linspace(1, 100, 100)

# 方法1: sympy计算, 速度很慢
# y1 = [float(f.subs(x, val).evalf()) for val in x_values]

# 方法2: sympy转numpy lambda表达式
f_lambda = sp.lambdify(x, f, 'numpy')
y2 = f_lambda(x_values)

# 方法3: numpy直接计算
y3 = (1 + 1 / x_values) ** x_values

fig = go.Figure(data=go.Scatter(x=x_values, y=y2, mode="lines"))
fig.show()
